fix: auto-recover PTY sessions after unexpected exit (WiFi drops)#17
Merged
wat-hiroaki merged 4 commits intomainfrom Mar 31, 2026
Merged
fix: auto-recover PTY sessions after unexpected exit (WiFi drops)#17wat-hiroaki merged 4 commits intomainfrom
wat-hiroaki merged 4 commits intomainfrom
Conversation
Two key changes: 1. Use `--resume <sessionId>` instead of `--session-id` when restarting a session that has an existing claudeSessionId. This restores the full conversation history after reconnection. 2. Add automatic retry on unexpected exit (non-zero, non-user-killed): - Up to 3 attempts with exponential backoff (2s, 4s, 8s) - Recovery counter resets once session becomes stable (active/thinking) - Skips retry if user explicitly stopped the session - Logs each attempt for debugging Fixes the issue where WiFi disconnection caused Claude CLI to exit with a network error, leaving sessions in 'error' state with no way to automatically resume. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dge cases - Filter extraEnvVars through denylist before merging with plugin env - Remove $ anchor from api.?key pattern to catch API_KEY_FILE variants - Wire PluginPermissions into PluginManifest type Closes #13 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add explanatory comment for DA response regex in utils.ts - Clean up CHANGELOG v0.9.1 to remove duplicate entries Closes #15 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
14 tests covering: - --resume vs --session-id argument construction (5 tests) - Auto-recovery counter with exponential backoff (4 tests) - User-initiated stop does NOT trigger recovery (3 tests) - Recovery counter resets on stable session (1 test) - Scrollback persistence during recovery (1 test) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes PTY session recovery after WiFi disconnection or network errors.
Problem: When WiFi drops, Claude CLI exits with a network error. The session goes to
errorstate and doesn't recover — even thoughclaudeSessionIdis preserved in the database. On manual restart, the conversation history was lost because--session-iddoesn't restore context.Root cause: Two issues:
startSessionalways used--session-id(starts fresh) instead of--resume(restores conversation)Changes:
--resumefor existing sessions: Whenagent.claudeSessionIdalready exists, use--resume <sessionId>instead of--session-id <sessionId>. This tells Claude CLI to restore the full conversation history.active/thinking/tool_running).isKilled). Re-reads agent from DB before retry to avoid stale state.Test plan
npm run lint— 0 errorsnpx tsc --noEmit— cleannpm run build— cleannpm test— 13/13 passnpm run dev— app starts without errors--session-idBehavior summary
error--resumerestores conversationidleidle(no retry)error, no more retries🤖 Generated with Claude Code